w={"zero": "0","one": "1","two": "2","three": "3","four": "4","five": "5","six": "6","seven": "7","eight": "8","nine": "9"}
y=input().split()
try:
    y = int("".join(map(lambda x: w[x], y)))
except Exception:
    print("Wrong input")
    exit(1)

def is_prime(y: int):
    for i in range(2, y):
        if y % i ==0:
            return False

    return True

less_prime = y
bigger_prime = y

while not is_prime(less_prime):
    less_prime -= 1

while not is_prime(bigger_prime):
    bigger_prime += 1

if y - less_prime < bigger_prime - y:
    print(less_prime)
else:
    print(bigger_prime)
